package Day01;

import java.util.HashMap;
import java.util.Map;

public class QuestionThree_NoRepeatStrMaxLength {
    public int lengthOfLongestSubstring(String s) {
        char[] charArr = s.toCharArray();
        Map<Character,Integer> map = new HashMap<>();
        int slow = 0,fast = 0, max = 0,n = s.length();
        for ( ; fast<n;fast++){
            char current = charArr[fast];
            if(map.containsKey(current)){
                slow = Math.max(slow,map.get(current)+1);
            }
            map.put(current,fast);
            max = Math.max(max,fast-slow+1);
        }
        return max;
    }
}
